﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VCC.Lib.Common;
namespace VCC.Model
{
    public class CounterManager
    {
        public static void Counter()
        {
            try
            {
                ChoVietDataContext eDataContext = new ChoVietDataContext();

                var c = eDataContext.Counters.Where(a => a.AddDate.Value.Day == DateTime.Now.Day &&
                    a.AddDate.Value.Month == DateTime.Now.Month &&
                    a.AddDate.Value.Year == DateTime.Now.Year).FirstOrDefault();
                if (c != null)
                {
                    c.Visited += 1;
                    eDataContext.SubmitChanges();
                }
                else
                {
                    c = new Counter();
                    c.Visited = 1;
                    c.AddDate = DateTime.Now;
                    eDataContext.Counters.InsertOnSubmit(c);
                    eDataContext.SubmitChanges();
                }
            }
            catch (Exception exp)
            {
               
            }
        }
    }
}
